<template>
	<view>
		<view class="tit">
			<image src="../../static/first/zs.png"></image>
			<view>关联您的公司信息</view>
		</view>
		<view class="content">
			<view class="phone">
				<text>企业名称</text>
				<input class="uni-input" v-model="query.name" focus placeholder="请输入您的企业名称" />
			</view>
			<view class="phone">
				<text>三证合一编号</text>
				<input class="uni-input" v-model="query.registrationNumber" focus placeholder="请输入三证合一编号" />
			</view>
			<view class="phone">
				<text>企业联系人</text>
				<input class="uni-input" v-model="query.contactPerson" focus placeholder="请输入企业联系人	" />
			</view>
			<view class="phone">
				<text>联系人手机号</text>
				<input class="uni-input" v-model="query.contactPhone" focus placeholder="请输入联系人手机号" />
			</view>
			<!-- <view class="phone">
				<text>验证码</text>
				<input class="uni-input" focus placeholder="请输入验证码" />
				<view class="getCode" @tap="getCode()" v-text="codeText" v-show="show"></view>
				<view class="getCode" v-show="!show">倒计时{{count}}秒</view>
			</view> -->
		</view>
		<view class="btn">
			<button @click="confirm">添加</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: true,
				codeText: "获取验证码",
				showBtnOn: false,
				timer: null,
				count: '',
				query: {
					name: '',
					registrationNumber: '',
					contactPerson: '',
					contactPhone: ''
				}
			}
		},
		methods: {
			//获取验证码
			getCode() {
				const TIME_COUNT = 60;
				if (!this.timer) {
					this.count = TIME_COUNT;
					this.show = false;
					this.timer = setInterval(() => {
						if (this.count > 0 && this.count <= TIME_COUNT) {
							this.count--;
						} else {
							this.show = true;
							clearInterval(this.timer);
							this.timer = null;
						}
					}, 1000)
				}
			},
			//提示
			showToast(title) {
				uni.showToast({
					title: title,
					icon: 'none'
				})
			},
			//添加企业信息
			confirm() {
				let that = this
				if (this.query.name == '') {
					that.showToast('企业名称不能为空')
				} else if (this.query.registrationNumber == '') {
					that.showToast('三证合一码不能为空')
				} else if (this.query.contactPerson == '') {
					that.showToast('企业联系人不能为空')
				} else if (this.query.contactPhone == '') {
					that.showToast('联系人姓名不能为空')
				} else {
					let userInfo = uni.getStorageSync('userInfo')
					uni.request({
						url: that.$serverUrl +'ftEnterprise',
						method: 'POST',
						data: {
							"userId": userInfo.id,
							"name": that.query.name,
							"registrationNumber": that.query.registrationNumber,
							"contactPerson": that.query.contactPerson,
							"contactPhone": that.query.contactPhone
						},
						success: (res) => {
							if (res.data.success) {
								uni.showToast({
									title: '添加成功',
									icon: 'none'
								})
							} else {
								uni.showToast({
									title: '添加失败',
									icon: 'none'
								})
							}
						}
					})
				}
			}
		}
	}
</script>

<style>
	page {
		width: 100%;
		height: 100%;
		background-color: #F5F5F5;
		overflow-y: hidden;
	}

	.tit {
		margin: 36upx;
		display: flex;
		align-items: flex-end;
	}

	.tit image {
		width: 22upx;
		height: 26upx;
	}

	.tit view {
		margin-left: 26upx;
		font-size: 32upx;
		font-weight: bold;
	}

	.content {
		background-color: #FFFFFF;
		color: #333333;
	}

	.phone {
		height: 124upx;
		display: flex;
		align-items: center;
	}

	.phone text {
		margin: 0 88upx 0 36upx;
	}

	.getCode {
		font-size: 28upx;
		color: #00B2CA;
	}

	/* 添加按钮 */
	.btn {
		width: 100%;
		height: 124upx;
		position: fixed;
		bottom: 0;
		background-color: #FFFFFF;
	}

	.btn button {
		margin: 0upx 36upx;
		background-color: #00B2CA;
		color: #FFFFFF;
	}
</style>
